package com.ruoyi.web.controller.depot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.depot.Monetary;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.depot.service.IMonetaryService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货币单位Controller
 * 
 * @author ruoyi
 * @date 2023-11-02
 */
@RestController
@RequestMapping("/depot/monetary")
public class MonetaryController extends BaseController
{
    @Autowired
    private IMonetaryService monetaryService;

    /**
     * 查询货币单位列表
     */
    @PreAuthorize("@ss.hasPermi('depot:monetary:list')")
    @GetMapping("/list")
    public TableDataInfo list(Monetary monetary)
    {
        startPage();
        List<Monetary> list = monetaryService.selectMonetaryList(monetary);
        return getDataTable(list);
    }

    /**
     * 导出货币单位列表
     */
    @PreAuthorize("@ss.hasPermi('depot:monetary:export')")
    @Log(title = "货币单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Monetary monetary)
    {
        List<Monetary> list = monetaryService.selectMonetaryList(monetary);
        ExcelUtil<Monetary> util = new ExcelUtil<Monetary>(Monetary.class);
        util.exportExcel(response, list, "货币单位数据");
    }

    /**
     * 获取货币单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('depot:monetary:query')")
    @GetMapping(value = "/{monetaryId}")
    public AjaxResult getInfo(@PathVariable("monetaryId") Long monetaryId)
    {
        return success(monetaryService.selectMonetaryByMonetaryId(monetaryId));
    }

    /**
     * 新增货币单位
     */
    @PreAuthorize("@ss.hasPermi('depot:monetary:add')")
    @Log(title = "货币单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Monetary monetary)
    {
        return toAjax(monetaryService.insertMonetary(monetary));
    }

    /**
     * 修改货币单位
     */
    @PreAuthorize("@ss.hasPermi('depot:monetary:edit')")
    @Log(title = "货币单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Monetary monetary)
    {
        return toAjax(monetaryService.updateMonetary(monetary));
    }

    /**
     * 删除货币单位
     */
    @PreAuthorize("@ss.hasPermi('depot:monetary:remove')")
    @Log(title = "货币单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{monetaryIds}")
    public AjaxResult remove(@PathVariable Long[] monetaryIds)
    {
        return toAjax(monetaryService.deleteMonetaryByMonetaryIds(monetaryIds));
    }
}
